import requests
import time
import os
import psutil


def request_minute():
    print("开始")
    for i in range(1000):
        req = requests.get("https://www.ncbi.nlm.nih.gov/")
        #os.system("timeout 60")
        print(f"第{i}次访问，结果为{req}\n60s 后进行下一次的访问")
        if get_inter() > 40:
            break


def get_inter():
    """Network speed. Unit = ** Kb/s"""
    sent_a = psutil.net_io_counters().bytes_sent
    recv_a = psutil.net_io_counters().bytes_recv
    time.sleep(1)
    sent_b = psutil.net_io_counters().bytes_sent
    recv_b = psutil.net_io_counters().bytes_recv
    print(f"上行{(sent_b - sent_a)/Download1024}，下行{(recv_b - recv_a)/Download1024}")
    return (recv_b - recv_a)/1024


request_minute()

"""
while True:
    if get_inter() < 40:
        requset_minute()
"""